package program;

import java.util.*;

public class Timetable {

	public Weekday[] weekDays;
	private Date startingDate;
	
	public Timetable(Date weekStartDate) {
		weekDays = new Weekday[7];
		startingDate = weekStartDate;
		for (int i=0; i<7; i++)
			weekDays[i] = new Weekday();
		
		//Sets the individual date for each weekday
		Date go;	
		for(int i = 0; i < 7; i++){
			go = new Date();
			go.setTime(weekStartDate.getTime() + (1000 * 60 * 60 * 24)*i);
			weekDays[i].setDate(go);
		}
	}
	
	public boolean validate(){
	    for(int i = 0; i< 7 ;i++){ 
	        if(weekDays[i].getList().isEmpty() == false){
	             if(weekDays[i].validateAll() == false){
	             return false;
	            }     
	        }
	    }
	    return true;
    }
        
    public void setStartingDate(Date weekStartDate){
        startingDate = weekStartDate;
    }
    
    public Weekday getWeekday(Date forThisDate){
    	for(int i = 0; i < weekDays.length; i++)
    		if(weekDays[i].getDate().getDate() == forThisDate.getDate())  //Checks day of month
    			if(weekDays[i].getDate().getMonth() == forThisDate.getMonth())  //Checks month
    				if(weekDays[i].getDate().getYear() == forThisDate.getYear())  //Checks year
    					return weekDays[i];
    	return new Weekday();
    }
    
    public Date getStartingDate(){
    	return startingDate;
    }
}
